﻿using DevExpress.XtraGrid.Columns;
using DevTeam;
using System;

namespace ConfExpert.Forms.Rapor.YeniYapi
{
    public partial class RafEtiketleri : XRapor
    {
        public RafEtiketleri()
        {
            InitializeComponent();
        }

        private void RafEtiketleri_Load(object sender, EventArgs e)
        {            
            this.Text = "Raf Etiketleri";

            gv.Init("GetBarcodeRAF", string.Empty);

            foreach (GridColumn gc in gv.Columns)
                if (gc.FieldName != "ShelfId" && gc.FieldName != "Name")
                    gc.Visible = false;

            gv.Columns["ShelfId"].ColumnEdit = null;
            gv.MakeReadOnly();
            gv.BestFitColumns();

            btnRapor1.ItemClick += btnRapor1_ItemClick;
            btnRapor2.ItemClick += btnRapor2_ItemClick;
            btnRapor3.ItemClick += btnRapor3_ItemClick;
        }

        void btnRapor3_ItemClick(object sender, DevExpress.XtraBars.ItemClickEventArgs e)
        {
            string raflar = Raflar;
            if (raflar != String.Empty)
            {
                Raf barcode = new Raf(Raflar);
                ReportViewer.View(barcode);
            }
        }

        void btnRapor2_ItemClick(object sender, DevExpress.XtraBars.ItemClickEventArgs e)
        {
            string raflar = Raflar;
            if (raflar != String.Empty)
            {
                EtiketRaf3 barcode = new EtiketRaf3(Raflar);
                ReportViewer.View(barcode);
            }
        }

        void btnRapor1_ItemClick(object sender, DevExpress.XtraBars.ItemClickEventArgs e)
        {
            string raflar = Raflar;
            if (raflar != String.Empty)
            {
                EtiketRaf barcode = new EtiketRaf(Raflar);
                ReportViewer.View(barcode);
            }
        }

        private string Raflar
        {
            get
            {
                string raflar = string.Empty;
                foreach (int rowHandle in gv.GetSelectedRows())
                {
                    string raf = gv.GetRowCellValue(rowHandle, "ShelfId").ToString();
                    raflar += raf + ",";
                }

                if (raflar.Substring(raflar.Length - 1, 1) == ",")
                    raflar = raflar.Substring(0, raflar.Length - 1);
                return raflar;
            }
        }
    }
}